import 'package:flutter/material.dart';
import 'package:huajianshe_app/common/load_image.dart';
import 'package:huajianshe_app/common/res.dart';
import 'package:huajianshe_app/pages/lesson/model/LessonModel.dart';
import 'package:huajianshe_app/widget/RoundedCornerWidget.dart';

class ChapterListPage extends StatelessWidget {

  final List<Chapter>? chapters;

  const ChapterListPage(this.chapters, {Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    if (chapters?.isNotEmpty == true) {
      return
        ColoredBox(color: Colors.white, child: Padding(padding: EdgeInsets.symmetric(vertical: 13),
            child: MediaQuery.removePadding(context: context, removeTop: true,
                child: ListView.separated(
                    itemBuilder: (BuildContext context, int index) {
                      Chapter chapter = chapters![index];
                      return RoundedCornerWidget(child: Column(crossAxisAlignment: CrossAxisAlignment.start, children: [
                        Text(chapter.name ?? '',  style: TS(14, C.gray333)),
                        H(6),
                        Row(children: [
                          LoadImage('ic_play_lesson_11'),
                          W(5),
                          Text('时长 ${chapter.length ?? ''}', style: TS(12, C.gray666),)
                        ])
                      ]), backgroundColor: C.grayF6, radius: 4, borderWidth: 0,
                        padding: EdgeInsets.symmetric(horizontal: 13, vertical: 15),
                        margin: EdgeInsets.symmetric(horizontal: 13),);
                    },
                    separatorBuilder: (BuildContext context, int index) { return H(5);},
                    itemCount: chapters!.length)
          )
        ));
    }
    return Center(child: Text('没有数据'),);
  }
}